package com.peng.leetcode.tree;

/**
 * FlipEquiv1
 * 951. 翻转等价二叉树
 * https://leetcode.cn/problems/flip-equivalent-binary-trees/
 *
 * @author: lupeng6
 * @create: 2023/2/5 12:20
 */
public class FlipEquiv1 {
    public boolean flipEquiv(TreeNode root1, TreeNode root2) {
        if (root1 == root2) {
            return true;
        }
        if (root1 == null || root2 == null || root1.val != root2.val) {
            return false;
        }
        return (flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right))
                || (flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left));
    }
}
